package com.ibeeking.found.cop.b.rest.service.mq;

import com.ibeeking.found.common.entity.MqMsgEventParam;
import com.ibeeking.found.cop.api.common.param.MsgEventDataTalkParam;
import com.ibeeking.found.cop.api.common.param.MsgEventDepartmentParam;
import com.ibeeking.found.cop.api.common.param.MsgEventFriendsParam;
import com.ibeeking.found.cop.b.rest.service.ICopDepartmentService;
import com.ibeeking.found.cop.b.rest.service.ICopEmployeeService;
import com.ibeeking.found.cop.b.rest.service.IFriendsService;
import com.ibeeking.found.cop.b.rest.service.IWxOpenService;
import com.ibeeking.nematos.log.utils.LogUtils;
import com.ibeeking.nematos.utils.data.StringUtils;
import com.ibeeking.nematos.utils.json.JsonUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

@Service
public class CopFriendsMqMsgEventHandler {

    @Resource
    private IFriendsService friendsServiceImpl;

    @Resource
    private IWxOpenService wxOpenServiceImpl;

    public boolean addFriendsMsgEvent(MqMsgEventParam mqParam, Map<String, Object> extMap) {
        try {
            LogUtils.info(">>>>>>> addFriendsMsgEvent:{}", JsonUtils.toJsonStr(mqParam));
            String tenantId = mqParam.getTenantId();
            //同步部门列表
            String paramStr = mqParam.getParams();
            if(StringUtils.isEmpty(paramStr)) {
                LogUtils.error("从MQ读取参数是空的！");
                return false;
            }
            MsgEventFriendsParam friendsParam = JsonUtils.fromJson(paramStr, MsgEventFriendsParam.class);
            String employeeCode = friendsParam.getEmployeeCode();
            String friendsCode = friendsParam.getFriendsCode();
            String welcomeCode = friendsParam.getWelcomeCode();
            String state = friendsParam.getState();

            return true;
        } catch (Exception e) {
            LogUtils.error("同步信息任务处理异常:{}", e);
            return false;
        }
    }

    public boolean updateFriendsMsgEvent(MqMsgEventParam mqParam, Map<String, Object> extMap) {
        try {
            LogUtils.info(">>>>>>> updateFriendsMsgEvent:{}", JsonUtils.toJsonStr(mqParam));
            String tenantId = mqParam.getTenantId();
            //同步部门列表
            String paramStr = mqParam.getParams();
            if(StringUtils.isEmpty(paramStr)) {
                LogUtils.error("从MQ读取参数是空的！");
                return false;
            }
            MsgEventFriendsParam friendsParam = JsonUtils.fromJson(paramStr, MsgEventFriendsParam.class);
            String employeeCode = friendsParam.getEmployeeCode();
            String friendsCode = friendsParam.getFriendsCode();

            return true;
        } catch (Exception e) {
            LogUtils.error("同步信息任务处理异常:{}", e);
            return false;
        }
    }

    public boolean deleteFriendsMsgEvent(MqMsgEventParam mqParam, Map<String, Object> extMap) {
        try {
            LogUtils.info(">>>>>>> deleteFriendsMsgEvent:{}", JsonUtils.toJsonStr(mqParam));
            String tenantId = mqParam.getTenantId();
            //同步部门列表
            String paramStr = mqParam.getParams();
            if(StringUtils.isEmpty(paramStr)) {
                LogUtils.error("从MQ读取参数是空的！");
                return false;
            }
            MsgEventFriendsParam friendsParam = JsonUtils.fromJson(paramStr, MsgEventFriendsParam.class);
            String employeeCode = friendsParam.getEmployeeCode();
            String friendsCode = friendsParam.getFriendsCode();
            String source = friendsParam.getSource();

            return true;
        } catch (Exception e) {
            LogUtils.error("同步信息任务处理异常:{}", e);
            return false;
        }
    }

    public boolean deleteFriendsFollowMsgEvent(MqMsgEventParam mqParam, Map<String, Object> extMap) {
        try {
            LogUtils.info(">>>>>>> createEmployeeMsgEvent:{}", JsonUtils.toJsonStr(mqParam));
            String tenantId = mqParam.getTenantId();
            //同步部门列表
            String paramStr = mqParam.getParams();
            if(StringUtils.isEmpty(paramStr)) {
                LogUtils.error("从MQ读取参数是空的！");
                return false;
            }
            MsgEventFriendsParam friendsParam = JsonUtils.fromJson(paramStr, MsgEventFriendsParam.class);
            String employeeCode = friendsParam.getEmployeeCode();
            String friendsCode = friendsParam.getFriendsCode();
            String source = friendsParam.getSource();

            return true;
        } catch (Exception e) {
            LogUtils.error("同步信息任务处理异常:{}", e);
            return false;
        }
    }

    public boolean addFriendsHalfMsgEvent(MqMsgEventParam mqParam, Map<String, Object> extMap) {
        try {
            LogUtils.info(">>>>>>> addFriendsHalfMsgEvent:{}", JsonUtils.toJsonStr(mqParam));
            String msgType = mqParam.getMsgType();
            String event = mqParam.getEvent();
            String changeType = mqParam.getChangeType();
            String tenantId = mqParam.getTenantId();
            //同步部门列表
            String paramStr = mqParam.getParams();
            if(StringUtils.isEmpty(paramStr)) {
                LogUtils.error("从MQ读取参数是空的！");
                return false;
            }
            MsgEventFriendsParam friendsParam = JsonUtils.fromJson(paramStr, MsgEventFriendsParam.class);
            String employeeCode = friendsParam.getEmployeeCode();
            String friendsCode = friendsParam.getFriendsCode();
            String welcomeCode = friendsParam.getWelcomeCode();
            String state = friendsParam.getState();

            return true;
        } catch (Exception e) {
            LogUtils.error("同步部门信息任务处理异常:{}", e);
            return false;
        }
    }

    public boolean tansferFailMsgEvent(MqMsgEventParam mqParam, Map<String, Object> extMap) {
        try {
            LogUtils.info(">>>>>>> tansferFailMsgEvent:{}", JsonUtils.toJsonStr(mqParam));
            String tenantId = mqParam.getTenantId();
            //同步部门列表
            String paramStr = mqParam.getParams();
            if(StringUtils.isEmpty(paramStr)) {
                LogUtils.error("从MQ读取参数是空的！");
                return false;
            }
            MsgEventFriendsParam friendsParam = JsonUtils.fromJson(paramStr, MsgEventFriendsParam.class);
            String employeeCode = friendsParam.getEmployeeCode();
            String friendsCode = friendsParam.getFriendsCode();
            String welcomeCode = friendsParam.getWelcomeCode();
            String state = friendsParam.getState();

            return true;
        } catch (Exception e) {
            LogUtils.error("同步信息任务处理异常:{}", e);
            return false;
        }
    }
    
}

